﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using NguyenHoa.Domains;
using NguyenHoa.Data;

#endregion

namespace NguyenHoa.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="NewsCategoryLocaleProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class NewsCategoryLocaleProviderBaseCore : EntityProviderBase<NguyenHoa.Domains.NewsCategoryLocale, NguyenHoa.Domains.NewsCategoryLocaleKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, NguyenHoa.Domains.NewsCategoryLocaleKey key)
		{
			return Delete(transactionManager, key.Id);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_id">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _id)
		{
			return Delete(null, _id);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _id);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblLanguage key.
		///		FK_tblNewsCategoryLocale_tblLanguage Description: 
		/// </summary>
		/// <param name="_languageId"></param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		public TList<NewsCategoryLocale> GetByLanguageId(System.Int32 _languageId)
		{
			int count = -1;
			return GetByLanguageId(_languageId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblLanguage key.
		///		FK_tblNewsCategoryLocale_tblLanguage Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_languageId"></param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		/// <remarks></remarks>
		public TList<NewsCategoryLocale> GetByLanguageId(TransactionManager transactionManager, System.Int32 _languageId)
		{
			int count = -1;
			return GetByLanguageId(transactionManager, _languageId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblLanguage key.
		///		FK_tblNewsCategoryLocale_tblLanguage Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_languageId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		public TList<NewsCategoryLocale> GetByLanguageId(TransactionManager transactionManager, System.Int32 _languageId, int start, int pageLength)
		{
			int count = -1;
			return GetByLanguageId(transactionManager, _languageId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblLanguage key.
		///		fkTblNewsCategoryLocaleTblLanguage Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_languageId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		public TList<NewsCategoryLocale> GetByLanguageId(System.Int32 _languageId, int start, int pageLength)
		{
			int count =  -1;
			return GetByLanguageId(null, _languageId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblLanguage key.
		///		fkTblNewsCategoryLocaleTblLanguage Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_languageId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		public TList<NewsCategoryLocale> GetByLanguageId(System.Int32 _languageId, int start, int pageLength,out int count)
		{
			return GetByLanguageId(null, _languageId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblLanguage key.
		///		FK_tblNewsCategoryLocale_tblLanguage Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_languageId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		public abstract TList<NewsCategoryLocale> GetByLanguageId(TransactionManager transactionManager, System.Int32 _languageId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblNewsCategory key.
		///		FK_tblNewsCategoryLocale_tblNewsCategory Description: 
		/// </summary>
		/// <param name="_newsCategoryId"></param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		public TList<NewsCategoryLocale> GetByNewsCategoryId(System.Int32 _newsCategoryId)
		{
			int count = -1;
			return GetByNewsCategoryId(_newsCategoryId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblNewsCategory key.
		///		FK_tblNewsCategoryLocale_tblNewsCategory Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_newsCategoryId"></param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		/// <remarks></remarks>
		public TList<NewsCategoryLocale> GetByNewsCategoryId(TransactionManager transactionManager, System.Int32 _newsCategoryId)
		{
			int count = -1;
			return GetByNewsCategoryId(transactionManager, _newsCategoryId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblNewsCategory key.
		///		FK_tblNewsCategoryLocale_tblNewsCategory Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_newsCategoryId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		public TList<NewsCategoryLocale> GetByNewsCategoryId(TransactionManager transactionManager, System.Int32 _newsCategoryId, int start, int pageLength)
		{
			int count = -1;
			return GetByNewsCategoryId(transactionManager, _newsCategoryId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblNewsCategory key.
		///		fkTblNewsCategoryLocaleTblNewsCategory Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_newsCategoryId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		public TList<NewsCategoryLocale> GetByNewsCategoryId(System.Int32 _newsCategoryId, int start, int pageLength)
		{
			int count =  -1;
			return GetByNewsCategoryId(null, _newsCategoryId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblNewsCategory key.
		///		fkTblNewsCategoryLocaleTblNewsCategory Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_newsCategoryId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		public TList<NewsCategoryLocale> GetByNewsCategoryId(System.Int32 _newsCategoryId, int start, int pageLength,out int count)
		{
			return GetByNewsCategoryId(null, _newsCategoryId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_tblNewsCategoryLocale_tblNewsCategory key.
		///		FK_tblNewsCategoryLocale_tblNewsCategory Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_newsCategoryId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of NguyenHoa.Domains.NewsCategoryLocale objects.</returns>
		public abstract TList<NewsCategoryLocale> GetByNewsCategoryId(TransactionManager transactionManager, System.Int32 _newsCategoryId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override NguyenHoa.Domains.NewsCategoryLocale Get(TransactionManager transactionManager, NguyenHoa.Domains.NewsCategoryLocaleKey key, int start, int pageLength)
		{
			return GetById(transactionManager, key.Id, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_tblNewsCategoryLocale index.
		/// </summary>
		/// <param name="_id"></param>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> class.</returns>
		public NguyenHoa.Domains.NewsCategoryLocale GetById(System.Int32 _id)
		{
			int count = -1;
			return GetById(null,_id, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblNewsCategoryLocale index.
		/// </summary>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> class.</returns>
		public NguyenHoa.Domains.NewsCategoryLocale GetById(System.Int32 _id, int start, int pageLength)
		{
			int count = -1;
			return GetById(null, _id, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblNewsCategoryLocale index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> class.</returns>
		public NguyenHoa.Domains.NewsCategoryLocale GetById(TransactionManager transactionManager, System.Int32 _id)
		{
			int count = -1;
			return GetById(transactionManager, _id, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblNewsCategoryLocale index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> class.</returns>
		public NguyenHoa.Domains.NewsCategoryLocale GetById(TransactionManager transactionManager, System.Int32 _id, int start, int pageLength)
		{
			int count = -1;
			return GetById(transactionManager, _id, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblNewsCategoryLocale index.
		/// </summary>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> class.</returns>
		public NguyenHoa.Domains.NewsCategoryLocale GetById(System.Int32 _id, int start, int pageLength, out int count)
		{
			return GetById(null, _id, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_tblNewsCategoryLocale index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> class.</returns>
		public abstract NguyenHoa.Domains.NewsCategoryLocale GetById(TransactionManager transactionManager, System.Int32 _id, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#region _tblNewsCategoryLocale_GetNewsCategoryLocale 
		
		/// <summary>
		///	This method wrap the '_tblNewsCategoryLocale_GetNewsCategoryLocale' stored procedure. 
		/// </summary>
		/// <param name="newsType"> A <c>System.String</c> instance.</param>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;NewsCategoryLocale&gt;"/> instance.</returns>
		public TList<NewsCategoryLocale> GetNewsCategoryLocale(System.String newsType, System.Int32? languageId)
		{
			return GetNewsCategoryLocale(null, 0, int.MaxValue , newsType, languageId);
		}
		
		/// <summary>
		///	This method wrap the '_tblNewsCategoryLocale_GetNewsCategoryLocale' stored procedure. 
		/// </summary>
		/// <param name="newsType"> A <c>System.String</c> instance.</param>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;NewsCategoryLocale&gt;"/> instance.</returns>
		public TList<NewsCategoryLocale> GetNewsCategoryLocale(int start, int pageLength, System.String newsType, System.Int32? languageId)
		{
			return GetNewsCategoryLocale(null, start, pageLength , newsType, languageId);
		}
				
		/// <summary>
		///	This method wrap the '_tblNewsCategoryLocale_GetNewsCategoryLocale' stored procedure. 
		/// </summary>
		/// <param name="newsType"> A <c>System.String</c> instance.</param>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;NewsCategoryLocale&gt;"/> instance.</returns>
		public TList<NewsCategoryLocale> GetNewsCategoryLocale(TransactionManager transactionManager, System.String newsType, System.Int32? languageId)
		{
			return GetNewsCategoryLocale(transactionManager, 0, int.MaxValue , newsType, languageId);
		}
		
		/// <summary>
		///	This method wrap the '_tblNewsCategoryLocale_GetNewsCategoryLocale' stored procedure. 
		/// </summary>
		/// <param name="newsType"> A <c>System.String</c> instance.</param>
		/// <param name="languageId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="TList&lt;NewsCategoryLocale&gt;"/> instance.</returns>
		public abstract TList<NewsCategoryLocale> GetNewsCategoryLocale(TransactionManager transactionManager, int start, int pageLength , System.String newsType, System.Int32? languageId);
		
		#endregion
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;NewsCategoryLocale&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;NewsCategoryLocale&gt;"/></returns>
		public static TList<NewsCategoryLocale> Fill(IDataReader reader, TList<NewsCategoryLocale> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				NguyenHoa.Domains.NewsCategoryLocale c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("NewsCategoryLocale")
					.Append("|").Append((System.Int32)reader[((int)NewsCategoryLocaleColumn.Id - 1)]).ToString();
					c = EntityManager.LocateOrCreate<NewsCategoryLocale>(
					key.ToString(), // EntityTrackingKey
					"NewsCategoryLocale",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new NguyenHoa.Domains.NewsCategoryLocale();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.Id = (System.Int32)reader[((int)NewsCategoryLocaleColumn.Id - 1)];
					c.NewsCategoryId = (System.Int32)reader[((int)NewsCategoryLocaleColumn.NewsCategoryId - 1)];
					c.LanguageId = (System.Int32)reader[((int)NewsCategoryLocaleColumn.LanguageId - 1)];
					c.Name = (System.String)reader[((int)NewsCategoryLocaleColumn.Name - 1)];
					c.Description = (reader.IsDBNull(((int)NewsCategoryLocaleColumn.Description - 1)))?null:(System.String)reader[((int)NewsCategoryLocaleColumn.Description - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, NguyenHoa.Domains.NewsCategoryLocale entity)
		{
			if (!reader.Read()) return;
			
			entity.Id = (System.Int32)reader[((int)NewsCategoryLocaleColumn.Id - 1)];
			entity.NewsCategoryId = (System.Int32)reader[((int)NewsCategoryLocaleColumn.NewsCategoryId - 1)];
			entity.LanguageId = (System.Int32)reader[((int)NewsCategoryLocaleColumn.LanguageId - 1)];
			entity.Name = (System.String)reader[((int)NewsCategoryLocaleColumn.Name - 1)];
			entity.Description = (reader.IsDBNull(((int)NewsCategoryLocaleColumn.Description - 1)))?null:(System.String)reader[((int)NewsCategoryLocaleColumn.Description - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, NguyenHoa.Domains.NewsCategoryLocale entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Id = (System.Int32)dataRow["Id"];
			entity.NewsCategoryId = (System.Int32)dataRow["NewsCategoryId"];
			entity.LanguageId = (System.Int32)dataRow["LanguageId"];
			entity.Name = (System.String)dataRow["Name"];
			entity.Description = Convert.IsDBNull(dataRow["Description"]) ? null : (System.String)dataRow["Description"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="NguyenHoa.Domains.NewsCategoryLocale"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">NguyenHoa.Domains.NewsCategoryLocale Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, NguyenHoa.Domains.NewsCategoryLocale entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region LanguageIdSource	
			if (CanDeepLoad(entity, "Language|LanguageIdSource", deepLoadType, innerList) 
				&& entity.LanguageIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.LanguageId;
				Language tmpEntity = EntityManager.LocateEntity<Language>(EntityLocator.ConstructKeyFromPkItems(typeof(Language), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.LanguageIdSource = tmpEntity;
				else
					entity.LanguageIdSource = DataRepository.LanguageProvider.GetById(transactionManager, entity.LanguageId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'LanguageIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.LanguageIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.LanguageProvider.DeepLoad(transactionManager, entity.LanguageIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion LanguageIdSource

			#region NewsCategoryIdSource	
			if (CanDeepLoad(entity, "NewsCategory|NewsCategoryIdSource", deepLoadType, innerList) 
				&& entity.NewsCategoryIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.NewsCategoryId;
				NewsCategory tmpEntity = EntityManager.LocateEntity<NewsCategory>(EntityLocator.ConstructKeyFromPkItems(typeof(NewsCategory), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.NewsCategoryIdSource = tmpEntity;
				else
					entity.NewsCategoryIdSource = DataRepository.NewsCategoryProvider.GetById(transactionManager, entity.NewsCategoryId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'NewsCategoryIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.NewsCategoryIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.NewsCategoryProvider.DeepLoad(transactionManager, entity.NewsCategoryIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion NewsCategoryIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the NguyenHoa.Domains.NewsCategoryLocale object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">NguyenHoa.Domains.NewsCategoryLocale instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">NguyenHoa.Domains.NewsCategoryLocale Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, NguyenHoa.Domains.NewsCategoryLocale entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region LanguageIdSource
			if (CanDeepSave(entity, "Language|LanguageIdSource", deepSaveType, innerList) 
				&& entity.LanguageIdSource != null)
			{
				DataRepository.LanguageProvider.Save(transactionManager, entity.LanguageIdSource);
				entity.LanguageId = entity.LanguageIdSource.Id;
			}
			#endregion 
			
			#region NewsCategoryIdSource
			if (CanDeepSave(entity, "NewsCategory|NewsCategoryIdSource", deepSaveType, innerList) 
				&& entity.NewsCategoryIdSource != null)
			{
				DataRepository.NewsCategoryProvider.Save(transactionManager, entity.NewsCategoryIdSource);
				entity.NewsCategoryId = entity.NewsCategoryIdSource.Id;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region NewsCategoryLocaleChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>NguyenHoa.Domains.NewsCategoryLocale</c>
	///</summary>
	public enum NewsCategoryLocaleChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Language</c> at LanguageIdSource
		///</summary>
		[ChildEntityType(typeof(Language))]
		Language,
			
		///<summary>
		/// Composite Property for <c>NewsCategory</c> at NewsCategoryIdSource
		///</summary>
		[ChildEntityType(typeof(NewsCategory))]
		NewsCategory,
		}
	
	#endregion NewsCategoryLocaleChildEntityTypes
	
	#region NewsCategoryLocaleFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;NewsCategoryLocaleColumn&gt;"/> class
	/// that is used exclusively with a <see cref="NewsCategoryLocale"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class NewsCategoryLocaleFilterBuilder : SqlFilterBuilder<NewsCategoryLocaleColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the NewsCategoryLocaleFilterBuilder class.
		/// </summary>
		public NewsCategoryLocaleFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the NewsCategoryLocaleFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public NewsCategoryLocaleFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the NewsCategoryLocaleFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public NewsCategoryLocaleFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion NewsCategoryLocaleFilterBuilder
	
	#region NewsCategoryLocaleParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;NewsCategoryLocaleColumn&gt;"/> class
	/// that is used exclusively with a <see cref="NewsCategoryLocale"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class NewsCategoryLocaleParameterBuilder : ParameterizedSqlFilterBuilder<NewsCategoryLocaleColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the NewsCategoryLocaleParameterBuilder class.
		/// </summary>
		public NewsCategoryLocaleParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the NewsCategoryLocaleParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public NewsCategoryLocaleParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the NewsCategoryLocaleParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public NewsCategoryLocaleParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion NewsCategoryLocaleParameterBuilder
	
	#region NewsCategoryLocaleSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;NewsCategoryLocaleColumn&gt;"/> class
	/// that is used exclusively with a <see cref="NewsCategoryLocale"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class NewsCategoryLocaleSortBuilder : SqlSortBuilder<NewsCategoryLocaleColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the NewsCategoryLocaleSqlSortBuilder class.
		/// </summary>
		public NewsCategoryLocaleSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion NewsCategoryLocaleSortBuilder
	
} // end namespace
